<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "org.json.simple.*, java.util.TreeMap, com.classes.Casemast, com.classes.CaseOutlet, java.util.ArrayList, java.net.URLEncoder" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>
<%
long merchant_id = 0;
long case_id = 0;
String app_no = "";
String request_type = "";
String bank = "";
String org_code = "027";
String wired_unit_required = "";
String wireless_unit_required = "";
String mpos_unit_required = "";
String wireless_terminal_sim_mbb = "";
String wireless_terminal_sim_vendor = "";
String merchant_name = "";
String acc_no = "";
String merchant_addr = "";
String marchant_pic = "";
String merchant_handphone = "";
String inst_remarks = "";
String mbb_officer = "";
String mbb_officer_handphone = "";
String trm_rental_wired_amt = "";
String trm_rental_wireless_amt = "";
String trm_deposit_amt = "";
JSONObject vendor_arr = null;
JSONObject vendor_details = null;
JSONObject stock_items = new JSONObject();
JSONArray card_types = new JSONArray();
JSONArray edc_programme = new JSONArray();
JSONObject appendix = new JSONObject();

ArrayList<TreeMap<String, String>> mdr_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> tid_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> pos_ezypay_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> amex_ezypay_facilities = new ArrayList<TreeMap<String, String>>();
JSONObject facilities = null;
JSONObject facility_tids = null;
JSONObject pos_ezypay = null;
JSONObject amex_ezypay = null;

if(request.getAttribute("m_case") != null){
	Casemast m_case = (Casemast) request.getAttribute("m_case");
	
	merchant_id = m_case.getMerchant().getId();
	case_id = m_case.getId();
	app_no = m_case.getReferenceNo();
	merchant_name = m_case.getMerchant().getRegisteredName();
}

CaseOutlet c_outlet = null;
if(request.getAttribute("c_outlet") != null) {
	c_outlet = (CaseOutlet) request.getAttribute("c_outlet");
	
	marchant_pic = c_outlet.getOutlet().getCTName();
	merchant_handphone = c_outlet.getOutlet().getCTTel();
	
	if(c_outlet.getOutlet().getPaymentOpt().length() > 0) {
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getPaymentOpt());
		acc_no = (obj.get("visa_2") == null) ? "" : obj.get("visa_2").toString();
	}
	
	if(c_outlet.getOutlet().getAddress().toString().length() > 0) {
		JSONObject obj = (JSONObject)JSONValue.parse(c_outlet.getOutlet().getAddress());
		
		String line_1 = (obj.get("line_1") == null) ? "" : obj.get("line_1").toString();
		String line_2 = (obj.get("line_2") == null) ? "" : obj.get("line_2").toString();	
		String line_3 = (obj.get("line_3") == null) ? "" : obj.get("line_3").toString();	
		String line_4 = (obj.get("line_4") == null) ? "" : obj.get("line_4").toString();	
		String postal_code = (obj.get("postal_code") == null) ? "" : obj.get("postal_code").toString();	
		String city = (obj.get("city") == null) ? "" : obj.get("city").toString();	
		String region_code = (obj.get("region_code") == null) ? "" : obj.get("region_code").toString();	
		
		merchant_addr = line_1 + (line_1.length() > 0 ? "\n" : "");
		merchant_addr += line_2 + (line_2.length() > 0 ? "\n" : "");
		merchant_addr += line_3 + (line_3.length() > 0 ? "\n" : "");
		merchant_addr += line_4 + (line_4.length() > 0 ? "\n" : "");
		
	}
	
	if(c_outlet.getRecommendation().length() > 0) {
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getRecommendation());
		wired_unit_required = (obj.get("no_of_wired_terminal") == null) ? "" : obj.get("no_of_wired_terminal").toString();
		wireless_unit_required = (obj.get("no_of_wireless_terminal") == null) ? "" : obj.get("no_of_wireless_terminal").toString();
		mpos_unit_required = (obj.get("no_of_mpos_terminal") == null) ? "" : obj.get("no_of_mpos_terminal").toString();
		
		String terminal_rental_amt = (obj.get("terminal_rental_amount") == null) ? "" : obj.get("terminal_rental_amount").toString();
		
		trm_rental_wired_amt = (obj.get("terminal_rental_wired") == null) ? "" : obj.get("terminal_rental_wired").toString();
		if(trm_rental_wired_amt.equals("")) {
			trm_rental_wired_amt = terminal_rental_amt.replace("RM ", "");
		}
		
		trm_rental_wireless_amt = (obj.get("terminal_rental_wireless") == null) ? "" : obj.get("terminal_rental_wireless").toString();
		
	}
	
	if(c_outlet.getPosForm().length() > 0){
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
		
		request_type = (obj.get("request_type") == null) ? "" : obj.get("request_type").toString();
		bank = (obj.get("bank") == null) ? "" : obj.get("bank").toString();
		org_code = (obj.get("org_code") == null) ? org_code : obj.get("org_code").toString();
		wired_unit_required = (obj.get("wired_unit_required") == null) ? wired_unit_required : obj.get("wired_unit_required").toString();
		wireless_unit_required = (obj.get("wireless_unit_required") == null) ? wireless_unit_required : obj.get("wireless_unit_required").toString();
		wireless_terminal_sim_mbb = (obj.get("wireless_terminal_sim_mbb") == null) ? "" : obj.get("wireless_terminal_sim_mbb").toString();
		wireless_terminal_sim_vendor = (obj.get("wireless_terminal_sim_vendor") == null) ? "" : obj.get("wireless_terminal_sim_vendor").toString();
		mpos_unit_required = (obj.get("mpos_unit_required") == null) ? mpos_unit_required : obj.get("mpos_unit_required").toString();
		merchant_name = (obj.get("merchant_name") == null) ? merchant_name : obj.get("merchant_name").toString();
		acc_no = (obj.get("acc_no") == null) ? acc_no : obj.get("acc_no").toString();
		merchant_addr = (obj.get("merchant_addr") == null) ? merchant_addr : obj.get("merchant_addr").toString();
		marchant_pic = (obj.get("marchant_pic") == null) ? marchant_pic : obj.get("marchant_pic").toString();
		merchant_handphone = (obj.get("merchant_handphone") == null) ? merchant_handphone : obj.get("merchant_handphone").toString();
		
		vendor_arr = (JSONObject) obj.get("vendor_arr");
		
		
		if(obj.get("edc_programme") != null) {
			edc_programme = (JSONArray) obj.get("edc_programme");
		}
		
		inst_remarks = (obj.get("inst_remarks") == null) ? "" : obj.get("inst_remarks").toString();
		mbb_officer = (obj.get("mbb_officer") == null) ? "" : obj.get("mbb_officer").toString();
		mbb_officer_handphone = (obj.get("mbb_officer_handphone") == null) ? "" : obj.get("mbb_officer_handphone").toString();
		
		trm_rental_wired_amt = (obj.get("trm_rental_wired_amt") == null) ? trm_rental_wired_amt : obj.get("trm_rental_wired_amt").toString();
		trm_rental_wireless_amt = (obj.get("trm_rental_wireless_amt") == null) ? trm_rental_wireless_amt : obj.get("trm_rental_wireless_amt").toString();
		trm_deposit_amt = (obj.get("trm_deposit_amt") == null) ? "" : obj.get("trm_deposit_amt").toString();
		
		if(obj.get("appendix") != null) {
			appendix = (JSONObject) obj.get("appendix");
		}
	}
	
}


String case_outlet_opt = "<option value=\"\"></option>";

if(request.getAttribute("c_outlets") != null) {
	ArrayList<CaseOutlet> c_outlets = ((ArrayList<CaseOutlet>)request.getAttribute("c_outlets"));

	for(CaseOutlet c : c_outlets) {
		case_outlet_opt += "<option value=\"" + c.getOutlet().getId() + "\">" + c.getOutlet().getName() + "</option>";
	}
}

if(request.getAttribute("c_outlet") != null) {
	case_outlet_opt = case_outlet_opt.replace("<option value=\"" + ((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getId() + "\">", "<option value=\"" + ((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getId() + "\" selected>");
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<title>MAYBANK</title>
<%
if(request.getAttribute("via_email") == null) {
%>	
<script src="<%= request.getContextPath() %>/js/vendor.js"></script>
<% 
}
%>
</head>
<body>

<!-- Header -->
<%@ include file="/jsp/common/_Header_Email.jsp" %>	
<!-- End Header -->

<div class="row-fluid page">
	<div class="span12">
		
		<div class="section-header">Vendor POS Form</div>
		
		<div class="form-horizontal">
			
			<div class="control-group">
				<label class="control-label">For Outlet</label>
				<div class="controls">
					<select id="outlet_id" name="outlet_id" readonly="readonly" style="width:220px"><%= case_outlet_opt %></select>
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">Request Type</label>
						<div class="controls">
							<select id="request_type" name="request_type" disabled="disabled">
							<% 
								String html = "<option value=\"\"></option>"
										+ "<option value=\"Installation\">Installation</option>"
										+ "<option value=\"Program\">Program</option>"
										+ "<option value=\"Tag-on\">Tag-on</option>";
								
								html = html.replace("<option value=\"" + request_type + "\">", "<option value=\"" + request_type + "\" selected />");		
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Application No.</label>
						<div class="controls">
							<input type="text" id="app_no" name="app_no" readonly="readonly" value="<%= app_no %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Organization Code</label>
						<div class="controls">
							<input type="text" id="org_code" name="org_code" readonly="readonly" value="<%= org_code %>" />
						</div>
					</div>
				
				</div>
				
				<div class="span6">
					
					<div class="control-group" <%= request_type.equals("Tag-on") ? "" : "style=\"visibility:hidden\"" %>>
						<label class="control-label">Bank</label>
						<div class="controls">
							<select id="bank" name="bank" disabled="disabled">
							<% 
								html = "<option value=\"\"></option>"
										+ "<option value=\"CIMB\">CIMB</option>"
										+ "<option value=\"HLB\">HLB</option>"
										+ "<option value=\"HSBC\">HSBC</option>"
										+ "<option value=\"ALLIANCE\">ALLIANCE</option>"
										+ "<option value=\"PBB\">PBB</option>"
										+ "<option value=\"RHB\">RHB</option>"
										+ "<option value=\"SCB\">SCB</option>"
										+ "<option value=\"CITIBANK\">CITIBANK</option>"
										+ "<option value=\"UOB\">UOB</option>"
										+ "<option value=\"OCBC\">OCBC</option>"
										+ "<option value=\"MBF\">MBF</option>"
										+ "<option value=\"Ambank\">Ambank</option>"
										+ "<option value=\"DINERS\">DINERS</option>";
								
								html = html.replace("<option value=\"" + bank + "\">", "<option value=\"" + bank + "\" selected />");		
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
				</div>
			</div>
			
			
			<div class="row-fluid">
				<div class="span12">
					<div class="control-group">
						<label class="control-label">No. of Unit Required</label>
						<div class="controls">
							<table class="tbl vendor_pos_tbl_1" style="width:90%;">
								<tr>
									<td style="width:15%">Wired</td>
									<td style="width:16%"><input type="text" id="wired_unit_required" name="wired_unit_required" readonly="readonly" value="<%= wired_unit_required %>" /></td>
									<td style="width:22%">Wireless</td>
									<td style="width:16%"><input type="text" id="wireless_unit_required" name="wireless_unit_required" readonly="readonly" value="<%= wireless_unit_required %>" /></td>
									<td style="width:15%">MPOS</td>
									<td style="width:16%"><input type="text" id="mpos_unit_required" name="mpos_unit_required" readonly="readonly" value="<%= mpos_unit_required %>" /></td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td>Terminal MBB + SIM MBB</td>
									<td>
										<% 
											String checked = "disabled ";
											if(wireless_terminal_sim_mbb.equals("Y")){
												checked += "checked";
											}
										%>
										<input type="checkbox" id="wireless_terminal_sim_mbb" name="wireless_terminal_sim_mbb" <%= checked %> value="Y" />
									</td>
								</tr>
								<tr>
									<td></td>
									<td></td>
									<td>Terminal Vendor + SIM Vendor</td>
									<td>
										<% 
											checked = "disabled ";
											if(wireless_terminal_sim_vendor.equals("Y")){
												checked += "checked";
											}
										%>
										<input type="checkbox" id="wireless_terminal_sim_vendor" name="wireless_terminal_sim_vendor" <%= checked %> value="Y" />
									</td>
								</tr>
							</table>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Merchant Name</label>
						<div class="controls">
							<input type="text" id="merchant_name" name="merchant_name" readonly="readonly" value="<%= merchant_name %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Current Account No.</label>
						<div class="controls">
							<input type="text" id="acc_no" name="acc_no" readonly="readonly" value="<%= acc_no %>" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Merchant Address</label>
						<div class="controls">
							<textarea id="merchant_addr" name="merchant_addr" readonly="readonly" rows="5"><%= merchant_addr %></textarea>
						</div>
					</div>
				</div>
			</div>
			
			
			<div class="row-fluid">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">Merchant PIC</label>
						<div class="controls">
							<input type="text" id="marchant_pic" name="marchant_pic" readonly="readonly" value="<%= marchant_pic %>" />
						</div>
					</div>
				</div>
				
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Handphone No.</label>
						<div class="controls">
							<input type="text" id="merchant_handphone" name="merchant_handphone" readonly="readonly" value="<%= merchant_handphone %>" />
						</div>
					</div>
				</div>
				
			</div>
			
		</div>
		
		
	</div>
</div>

<%
String partner_name = (String) request.getAttribute("partner_name");

for(Object vname : vendor_arr.keySet()) {
	vendor_details = (JSONObject) vendor_arr.get(vname);
	
	if(vendor_details != null){
		if(vendor_details.get("stock_items") != null) {
			stock_items = (JSONObject) vendor_details.get("stock_items");
		}
		
		if(vendor_details.get("card_types") != null) {
			card_types = (JSONArray) vendor_details.get("card_types");
		}
		
		if(vendor_details.get("mdr_facilities") != null) {
			facilities = (JSONObject) vendor_details.get("mdr_facilities");
		}
		
		if(vendor_details.get("facility_tids") != null) {
			facility_tids = (JSONObject) vendor_details.get("facility_tids");
		}
		
		if(vendor_details.get("pos_ezypay_facilities") != null) {
			pos_ezypay = (JSONObject) vendor_details.get("pos_ezypay_facilities");
		}
		
		if(vendor_details.get("amex_ezypay_facilities") != null) {
			amex_ezypay = (JSONObject) vendor_details.get("amex_ezypay_facilities");
		}
		
		
		if(partner_name.startsWith("Vendor - ")) {
			String vendor_name2 = partner_name.substring(new String("Vendor - ").length());
			if(vendor_details.get("name2").toString().equals(vendor_name2) == false) {
				continue;
			}
		}
	}
	else {
		continue;
	}
	
	
	if(c_outlet.getOutlet().getMDRRate().length() > 0){
		JSONObject mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		
		String[] arr = new String[] {"POS", "DCC", "MO", "TO", "RPS", "E-Commerce", "M2U", "ORS"};
		String[] arr_type = new String[] {"Wired", "Wireless", "MPOS"};
		String[] arr_ezpay = new String[] {"E3", "E6", "E9", "E12", "E18", "E24", "E36"};
		
		for(String s : arr){
			String in_mid = "";
			String in_mid_amex = "";
			
			if(s.equals("POS")){
				in_mid = mdr_obj.get("14").toString();	// VISA MASTER POS MID No
				in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			} else if(s.equals("DCC")){
				in_mid = mdr_obj.get("15").toString();	// VISA MASTER DCC MID No
				in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			} else if(s.equals("MO")){
				in_mid = mdr_obj.get("16").toString();	// VISA MASTER MO MID No
				in_mid_amex = mdr_obj.get("284").toString();	// AMEX MO Amex MID No
			} else if(s.equals("TO")){
				in_mid = mdr_obj.get("17").toString();	// VISA MASTER TO MID No
				in_mid_amex = mdr_obj.get("285").toString();	// AMEX TO Amex MID No
			} else if(s.equals("RPS")){
				in_mid = mdr_obj.get("18").toString();	// VISA MASTER RPS MID No
				in_mid_amex = mdr_obj.get("286").toString();	// AMEX RPS Amex MID No
			} else if(s.equals("E-Commerce")){
				in_mid = mdr_obj.get("19").toString();	// VISA MASTER E-Commerce MID No
				in_mid_amex = mdr_obj.get("287").toString();	// AMEX E-Commerce Amex MID No
			} else if(s.equals("M2U")){
				in_mid = mdr_obj.get("20").toString();	// VISA MASTER M2U MID No
				in_mid_amex = mdr_obj.get("288").toString();	// AMEX M2U Amex MID No
			} else if(s.equals("ORS")){
				in_mid = mdr_obj.get("21").toString();	// VISA MASTER ORS MID No
				in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			}
			
			if(in_mid_amex.startsWith("01")) {
				in_mid_amex = in_mid_amex.replaceFirst("01", "920");
			}
			
			TreeMap<String, String> item = null;
			
			if(in_mid.length() > 0 || in_mid_amex.length() > 0){
				for(String t  : arr_type) {
					item = new TreeMap<String, String>();
					item.put("facility", s);
					item.put("mid_no", in_mid);
					item.put("mid_no2", in_mid_amex);
					item.put("type", t);
					item.put("first_tid", "");
					item.put("tid_items", "");
					
					if(facilities != null && facilities.get(s) != null){
						JSONObject f_type_obj = (JSONObject) facilities.get(s);
						JSONObject f_obj = (JSONObject) f_type_obj.get(t);
						item.put("first_tid", f_obj.get("first_tid").toString());
						item.put("tid_items", f_obj.get("tid_items").toString());
					}
					
					mdr_facilities.add(item);
					
					
					if(facility_tids != null) {
						if(facility_tids.get(s) != null) {
							JSONObject tid_type_obj = (JSONObject) facility_tids.get(s);
							
							if(tid_type_obj.get(t) != null) {
								JSONArray tid_obj = (JSONArray) tid_type_obj.get(t);
								
								for(int i=0; i<tid_obj.size(); i++){
									JSONObject tid_item = (JSONObject) tid_obj.get(i);
									
									item = new TreeMap<String, String>();
									item.put("facility", s);
									item.put("type", t);
									item.put("mid_no", tid_item.get("mid_no").toString());
									item.put("mid_no2", (tid_item.get("mid_no2") == null ? "" : tid_item.get("mid_no2").toString()));
									item.put("tid_no", tid_item.get("tid_no").toString());
									
									tid_facilities.add(item);
									
									
									String tid_no_str = tid_item.get("tid_no").toString();
									
									if(pos_ezypay != null && pos_ezypay.containsKey(tid_no_str)){
										JSONObject pos_ezypay_arr = (JSONObject) pos_ezypay.get(tid_no_str);
										
										for(String ezpay : arr_ezpay){
											if(pos_ezypay_arr.get(ezpay) == null){
												continue;
											}
											
											JSONObject pos_ezypay_item = (JSONObject) pos_ezypay_arr.get(ezpay);
											
											item = new TreeMap<String, String>();
											item.put("tid_no", pos_ezypay_item.get("tid_no").toString());
											item.put("type", pos_ezypay_item.get("type").toString());
											item.put("ezypay_plan", pos_ezypay_item.get("ezypay_plan").toString());
											item.put("mid_no", pos_ezypay_item.get("mid_no").toString());
											item.put("first_tid", pos_ezypay_item.get("first_tid").toString());
											
											pos_ezypay_facilities.add(item);
										}
										
									}
										
									
									if(amex_ezypay != null && amex_ezypay.containsKey(tid_no_str)){
										JSONObject amex_ezypay_arr = (JSONObject) amex_ezypay.get(tid_no_str);
										
										for(String ezpay : arr_ezpay){
											if(amex_ezypay_arr.get(ezpay) == null){
												continue;
											}
											
											JSONObject amex_ezypay_item = (JSONObject) amex_ezypay_arr.get(ezpay);
											
											item = new TreeMap<String, String>();
											item.put("tid_no", amex_ezypay_item.get("tid_no").toString());
											item.put("type", amex_ezypay_item.get("type").toString());
											item.put("ezypay_plan", amex_ezypay_item.get("ezypay_plan").toString());
											item.put("mid_no", amex_ezypay_item.get("mid_no").toString());
											item.put("first_tid", amex_ezypay_item.get("first_tid").toString());
											
											amex_ezypay_facilities.add(item);
										}
									}
									
								}
							}
						}
					}
				}
				
				
				
			}
		}
	}
%>
<div class="row-fluid page">
	<div class="span12">
		
		<div class="section-header"><%= vname.toString() %></div>
		
		<div class="form-section">
			<table class="tbl vendor_pos_tbl_1 stock_items" style="width:70%"><thead>
				<tr>
					<th style="width:25%">Serial No.</th>
					<th style="width:25%">Wired</th>
					<th style="width:25%">Wireless</th>
					<th style="width:25%">MPOS</th>
				</tr>
			</thead><tbody>
				<tr>
					<%
					String serialNo = vendor_details == null || vendor_details.get("serial_no") == null ? "" : vendor_details.get("serial_no").toString();
					String wired = stock_items.get("wired") == null ? "" : stock_items.get("wired").toString();
					String wireless = stock_items.get("wireless") == null ? "" : stock_items.get("wireless").toString();
					String mpos = stock_items.get("mpos") == null ? "" : stock_items.get("mpos").toString();
					%>
					<td class="input serialno"><input type="text" readonly="readonly" value="<%=serialNo %>" /></td>
					<td class="input wired"><input type="text" readonly="readonly" value="<%=wired %>" /></td>
					<td class="input wireless"><input type="text" readonly="readonly" value="<%=wireless %>" /></td>
					<td class="input mpos"><input type="text" readonly="readonly" value="<%=mpos %>" /></td>
				</tr>
			</tbody></table>
		</div>
		
		<div class="form-section">
			<div class="title">POS TIDs</div>
			<table class="tbl vendor_pos_tbl_2 mdr_facilities" style="width:70%; margin-bottom:20px"><thead>
				<tr>
					<th style="width:20%">FACILITY</th>
					<th style="width:20%">POS MID</th>
					<th style="width:20%">AMEX MID</th>
					<th style="width:20%">Type</th>
					<th style="width:20%">First TID No.</th>
					<th style="width:20%">Number of TID</th>
				</tr>
			</thead><tbody>
				<%
					for(TreeMap<String, String> item : mdr_facilities){
						html = "<tr>"
							+ "	<td class=\"facility\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("facility") + "\" /></td>"
							+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
							+ "	<td class=\"mid_no2\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no2") + "\" /></td>"
							+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + (item.get("type") == null ? "" : item.get("type")) + "\" /></td>"
							+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("first_tid") + "\" /></td>"
							+ "	<td class=\"tid_items\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_items") + "\" /></td>"
							+ "</tr>";
						
						out.println(html);
					}
				%>
			</tbody></table>
			
		</div>
		
		<div class="form-section">
			<table class="tbl vendor_pos_tbl_2" style="width:52.5%"><thead>
				<tr>
					<th style="width:20%">FACILITY</th>
					<th style="width:20%">POS MID</th>
					<th style="width:20%">AMEX MID</th>
					<th style="width:20%">Type</th>
					<th style="width:20%">TID No.</th>
				</tr>
			</thead><tbody>
				<%
					for(TreeMap<String, String> item : tid_facilities){
						html = "<tr>"
							+ "	<td class=\"facility\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("facility") + "\" /></td>"
							+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
							+ "	<td class=\"mid_no2\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no2") + "\" /></td>"
							+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + (item.get("type") == null ? "" : item.get("type")) + "\" /></td>"
							+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
							+ "</tr>";
						
						out.println(html);
					}
				%>
			</tbody></table>
		</div>
		
		<div class="form-section">
			<table class="vendor_card_type"><tbody>
			<% 
				html = "<tr>"
					+ "	<th>CARD TYPE</th>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"VISA\">VISA</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"MASTER\">MASTER</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"JCB\">JCB</label></td>"
					+ "</tr>"
					+ "<tr>"
					+ "	<td></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"AMEX\">AMEX</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"MAESTRO\">MAESTRO</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"DEBIT CARD\">DEBIT CARD</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" name=\"card_type\" disabled=\"disabled\" value=\"Union Pay\">Union Pay</label></td>"
					+ "</tr>";
				
				for(Object s : card_types){
					String s1 = (String) s;
					html = html.replace("value=\"" + s1 + "\"", "value=\"" + s1 + "\" checked ");
				}
				
				out.println(html);
			%>
			</tbody></table>
		</div>
		
		
		<div class="form-section">
			<div class="title">POS (EZYPAY)</div>
			<table class="tbl vendor_pos_tbl_2 pos_ezypay" style="width:75%; margin-bottom:20px"><thead>
				<tr>
					<th style="width:20%">POS TID</th>
					<th style="width:20%">Type</th>
					<th style="width:20%">EZYPAY Plan</th>
					<th style="width:20%">EZYPAY MID</th>
					<th style="width:20%">EZYPAY TID</th>
				</tr>
			</thead><tbody>
			<%
				String last_parent_tid = "";
				for(TreeMap<String, String> item : pos_ezypay_facilities){
					String read_only = "readonly=\"readonly\"";
					
					if(item.get("tid_no").equals(last_parent_tid) == false) {
						read_only = "";
						last_parent_tid = item.get("tid_no");
					}
					
					html = "<tr data-tid=\"" + item.get("tid_no") + "\">"
						+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
						+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + (item.get("type") == null ? "" : item.get("type") ) + "\" /></td>"
						+ "	<td class=\"ezypay_plan\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("ezypay_plan") + "\" /></td>"
						+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
						+ "	<td class=\"first_tid\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("first_tid") + "\" /></td>"
						+ "</tr>";
					
					out.println(html);
				}
			%>
			</tbody></table>
		</div>
		
		
		
		<div class="form-section">
			<div class="title">AMEX (EZYPAY)</div>
			<table class="tbl vendor_pos_tbl_2 amex_ezypay" style="width:75%; margin-bottom:20px"><thead>
				<tr>
					<th style="width:20%">POS TID</th>
					<th style="width:20%">Type</th>
					<th style="width:20%">EZYPAY Plan</th>
					<th style="width:20%">EZYPAY MID</th>
					<th style="width:20%">EZYPAY TID</th>
				</tr>
			</thead><tbody>
			<%
				last_parent_tid = "";
				for(TreeMap<String, String> item : amex_ezypay_facilities){
					String read_only = "readonly=\"readonly\"";
					
					if(item.get("tid_no").equals(last_parent_tid) == false) {
						read_only = "";
						last_parent_tid = item.get("tid_no");
					}
					
					html = "<tr data-tid=\"" + item.get("tid_no") + "\">"
						+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
						+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("type") + "\" /></td>"
						+ "	<td class=\"ezypay_plan\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("ezypay_plan") + "\" /></td>"
						+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
						+ "	<td class=\"first_tid\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("first_tid") + "\" /></td>"
						+ "</tr>";
					
					out.println(html);
				}
			%>
			</tbody></table>
		</div>
		
		
		<div class="form-section">
			<table class="tbl vendor_pos_tbl_1" style="width:60%">
				<tr>
					<td style="width:30%">
						<% 
							checked = "disabled ";
							String mid_no = "";
							
							if(vendor_details != null){
								if(vendor_details.get("diners_select") != null && vendor_details.get("diners_select").toString().equals("Y")){
									checked += "checked";
								}
								
								if(vendor_details.get("diners_mid") != null){
									mid_no = vendor_details.get("diners_mid").toString();
								}
							}
						%>
						<label class="checkbox"><input id="diners_select" name="diners_select" type="checkbox" <%=checked %> value="Y" /> DINERS</label>
					</td>
					<td style="width:70%">MID &nbsp; <input id="diners_mid" name="diners_mid" type="text" readonly="readonly" value="<%=mid_no %>" style="width:243px" /></td>
				</tr>
				<tr>
					<td>
						<% 
							checked = "disabled ";
							mid_no = "";
						
							if(vendor_details != null){
								if(vendor_details.get("aeon_select") != null && vendor_details.get("aeon_select").toString().equals("Y")){
									checked += "checked";
								}
								
								if(vendor_details.get("diners_mid") != null){
									mid_no = vendor_details.get("diners_mid").toString();
								}
							}
						%>
						<label class="checkbox"><input id="aeon_select" name="aeon_select" type="checkbox" <%=checked %> value="Y" /> AEON</label>
					</td>
					<td>MID &nbsp; <input id="aeon_mid" name="aeon_mid" type="text" readonly="readonly" value="<%=mid_no %>" style="width:243px" /></td>
				</tr>
				<tr>
					<td>
						<% 
							checked = "disabled ";
							mid_no = "";
						
							if(vendor_details != null){
								if(vendor_details.get("genting_select") != null && vendor_details.get("genting_select").toString().equals("Y")){
									checked += "checked";
								}
								
								if(vendor_details.get("genting_mid") != null){
									mid_no = vendor_details.get("genting_mid").toString();
								}
							}
						%>
						<label class="checkbox"><input id="genting_select" name="genting_select" type="checkbox" <%=checked %> value="Y" /> GENTING</label>
					</td>
					<td>MID &nbsp; <input id="genting_mid" name="genting_mid" type="text" readonly="readonly" value="<%=mid_no %>" style="width:243px" /></td>
				</tr>
			</table>
		</div>
		
	</div>
</div>

<%
}
%>

<div class="row-fluid page" style="min-height:0px">
	<div class="span12">
		
		<div class="form-section">
			<div class="title">EDC PROGRAMME (FUNCTION)</div>
			<table class="tbl vendor_pos_tbl_1 edc_programme" style="width:80%"><tbody>
			<%
				html = "<tr>"
					+ "	<td style=\"width:25%\"><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Card Verification\">Card Verification</label></td>"
					+ "	<td style=\"width:25%\"><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Offline\">Offline</label></td>"
					+ "	<td style=\"width:25%\"><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Manual Key-In\">Manual Key-In</label></td>"
					+ "	<td style=\"width:25%\"><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"DCC\">DCC</label></td>"
					+ "</tr>"
					+ "<tr>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Cash Advance\">Cash Advance</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Tips\">Tips</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Refund\">Refund</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Other\">Other</label></td>"
					+ "</tr>"
					+ "<tr>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Cash Back\">Cash Back</label></td>"
					+ "	<td><label class=\"checkbox\"><input type=\"checkbox\" disabled=\"disabled\" value=\"Prepaid Card Reload\">Prepaid Card Reload</label></td>"
					+ "</tr>";
					
				for(Object s : edc_programme){
					String s1 = (String) s;
					html = html.replace("value=\"" + s1 + "\"", "value=\"" + s1 + "\" checked ");
				}
				
				out.println(html);
			%>
			</tbody></table>
			
			<table class="tbl vendor_pos_tbl_1" style="width:80%; margin-top:20px">
				<tr>
					<td>Installation Remaks</td>
					<td colspan="3"><textarea id="inst_remarks" name="inst_remarks" readonly="readonly" style="width:95%; height:60px; margin-bottom:0px"><%=inst_remarks %></textarea></td>
				</tr>
				<tr>
					<td>MBB Officer In Charge</td>
					<td><input type="text" id="mbb_officer" name="mbb_officer" readonly="readonly" value="<%=mbb_officer %>" style="width:150px" /></td>
					<td>Handphone No.</td>
					<td><input type="text" id="mbb_officer_handphone" name="mbb_officer_handphone" readonly="readonly" value="<%=mbb_officer_handphone %>" style="width:150px" /></td>
				</tr>
			</table>
		</div>
	</div>
</div>
		<%
		if(request.getAttribute("via_email") == null) {
			int outlet_id = (int) ((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getId();
		%>
<div class="row-fluid page" style="min-height:0px">
	<div class="span12">
		<form name="form" class="form-horizontal" style="margin-top:30px">
			<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
			<div class="control-group">
				<label class="control-label" style="text-align:left">Email POS Form :</label>
				<div class="controls">
					<input name="email" type="text" placeholder="Email address" value="<%= request.getAttribute("email_addr").toString() %>" />
					<button id="notify" type="button" class="btn" onclick="vendor.create_appendix_partner(<%= merchant_id %>, <%= case_id %>, <%= outlet_id %>, '<%= (String) request.getAttribute("partner_name") %>')">Notify via Email</button>
				</div>
			</div>
		</form>
		
	</div>
</div>
		<%
		}
		%>



</body>
</html>